package movies.repositoryHibernate;

import java.util.List;
import movies.domain.EventCategory;
import movies.repository.IEventCategoryRepository;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author Hanna_Aliakseichykava
 */
public class EventCategoryRepository extends HibernateDaoSupport
implements IEventCategoryRepository{

    @Override
    public EventCategory getEventCategoryById(int id) {
        List < EventCategory > eventCategories = getHibernateTemplate().
             findByNamedQuery("GetEventCategoryById", id);

        if (eventCategories.size() == 1) {
            return eventCategories.get(0);
        } else {
            return null;
        }
    }

    @Override
    public EventCategory getEventCategoryByName(String name) {
        List < EventCategory > eventCategories = getHibernateTemplate().
             findByNamedQuery("GetEventCategoryByName", name);

        if (eventCategories.size() == 1) {
            return eventCategories.get(0);
        } else {
            return null;
        }
    }

    @Override
    public List<EventCategory> getAllEventCategories() {
        List < EventCategory > eventCategories = getHibernateTemplate().
             findByNamedQuery("GetAllEventCategories");

        if (eventCategories.size() > 0) {
            return eventCategories;
        } else {
            return null;
        }
    }

}
